package neusoft.edu.cn.a215lmeordering.model;


import neusoft.edu.cn.a215lmeordering.Listener.Listener;
import neusoft.edu.cn.a215lmeordering.bean.FoodDetails;
import neusoft.edu.cn.a215lmeordering.bean.Login;
import neusoft.edu.cn.a215lmeordering.service.AllService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class FoodDetailsModel {

    private Retrofit retrofit;

    public FoodDetailsModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(int food_id,final Listener Listener){

        AllService allService = retrofit.create(AllService.class);

        Call<FoodDetails> Call = allService.getFoodDetails(food_id);

        Call.enqueue(new Callback<FoodDetails>() {
                @Override
                public void onResponse(Call<FoodDetails> call, Response<FoodDetails> response) {
                    if(response!=null)
                        Listener.onResponse(response.body());
                    else Listener.onFail("获取信息失败");
                }

            @Override
            public void onFailure(Call<FoodDetails> call, Throwable t) {
                Listener.onFail(t.toString());
            }
        });
    }
}
